package com.bytedance.frameworks.baselib.network.http.parser;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;

public final class b {
    Hashtable a;

    public b() {

        this.a = new Hashtable();
    }

    public b(String arg2) throws MimeTypeParseException {

        this.a = new Hashtable();
        this.a(arg2);
    }

    private static int a(String arg2, int arg3) {
        int v0 = arg2.length();
        while (arg3 < v0) {
            if (!Character.isWhitespace(arg2.charAt(arg3))) {
                return arg3;
            }

            ++arg3;
        }

        return arg3;
    }

    private static boolean a(char arg1) {
        boolean v0 = arg1 <= 32 || arg1 >= 127 || "()<>@,;:/[]?=\\\"".indexOf(arg1) >= 0 ? false : true;
        return v0;
    }

    private static String b(String arg10) {
        char v9 = '\\';
        char v8 = '\"';
        int v1 = 0;
        int v3 = arg10.length();
        int v2 = 0;
        int v0 = 0;
        while (v2 < v3) {
            if (v0 != 0) {
                break;
            }

            v0 = !b.a(arg10.charAt(v2)) ? 1 : 0;
            ++v2;
        }

        if (v0 != 0) {
            StringBuffer v0_1 = new StringBuffer();
            v0_1.ensureCapacity(((int) ((((double) v3)) * 1.5)));
            v0_1.append(v8);
            while (v1 < v3) {
                char v2_1 = arg10.charAt(v1);
                if (v2_1 == v9 || v2_1 == v8) {
                    v0_1.append(v9);
                }

                v0_1.append(v2_1);
                ++v1;
            }

            v0_1.append(v8);
            arg10 = v0_1.toString();
        }

        return arg10;
    }

    private static String c(String arg7) {
        int v3 = arg7.length();
        StringBuffer v4 = new StringBuffer();
        v4.ensureCapacity(v3);
        int v2 = 0;
        int v0 = 0;
        while (v2 < v3) {
            char v5 = arg7.charAt(v2);
            if (v0 == 0 && v5 != 92) {
                v4.append(v5);
            } else if (v0 != 0) {
                v4.append(v5);
                v0 = 0;
            } else {
                v0 = 1;
            }

            ++v2;
        }

        return v4.toString();
    }

    private void a(String arg9) throws MimeTypeParseException {
        int v2;
        int v6 = 34;
        if (arg9 != null) {
            int v3 = arg9.length();
            if (v3 > 0) {
                int v0 = b.a(arg9, 0);
                while (v0 < v3) {
                    if (arg9.charAt(v0) != 59) {
                        break;
                    }

                    int v1 = b.a(arg9, v0 + 1);
                    if (v1 < v3) {
                        for (v0 = v1; v0 < v3; ++v0) {
                            if (!b.a(arg9.charAt(v0))) {
                                break;
                            }
                        }

                        String v4 = arg9.substring(v1, v0).toLowerCase(Locale.ENGLISH);
                        v0 = b.a(arg9, v0);
                        if (v0 < v3 && arg9.charAt(v0) == 61) {
                            v0 = b.a(arg9, v0 + 1);
                            String v0_1;
                            if (v0 >= v3) {
                                throw new MimeTypeParseException("Couldn\'t find a value for parameter named " + v4);
                            } else {
                                char v1_1 = arg9.charAt(v0);
                                if (v1_1 == v6) {
                                    v2 = v0 + 1;
                                    if (v2 >= v3) {
                                        throw new MimeTypeParseException("Encountered unterminated quoted parameter value.");
                                    } else {
                                        v0 = v2;
                                        while (v0 < v3) {
                                            v1 = arg9.charAt(v0);
                                            if (v1 == v6) {
                                                break;
                                            }

                                            if (v1 == 92) {
                                                ++v0;
                                            }

                                            ++v0;
                                        }

                                        if (v1 != v6) {
                                            throw new MimeTypeParseException("Encountered unterminated quoted parameter value.");
                                        }
                                        v1 = v0 + 1;
                                        v0_1 = b.c(arg9.substring(v2, v0));
                                    }
                                } else if (b.a(v1_1)) {
                                    v1 = v0;
                                    label_79:
                                    while (v1 < v3) {
                                        if (!b.a(arg9.charAt(v1))) {
                                            break;
                                        }
                                        ++v1;
                                    }
                                    v0_1 = arg9.substring(v0, v1);
                                } else {
                                    throw new MimeTypeParseException("Unexpected character encountered at index " + v0);
                                }
                            }
                            this.a.put(v4, v0_1);
                            v0 = b.a(arg9, v1);
                            continue;
                        }
                        throw new MimeTypeParseException("Couldn\'t find the \'=\' that separates a parameter name from its value.");
                    } else {
                        return;
                    }
                }

                if (v0 >= v3) {
                    return;
                }

                throw new MimeTypeParseException("More characters encountered in input than expected.");
            }
        }
    }

    public final String toString() {
        StringBuffer v1 = new StringBuffer();
        v1.ensureCapacity(this.a.size() << 4);
        Enumeration v2 = this.a.keys();
        while (v2.hasMoreElements()) {
            Object v0 = v2.nextElement();
            v1.append("; ");
            v1.append(((String) v0));
            v1.append('=');
            v1.append(b.b((String) this.a.get(v0)));
        }

        return v1.toString();
    }
}

